"""SMTP设置页面"""
from page.base_page import BasePage
from selenium.webdriver.common.by import By
from config.config import PROJECT_PATH
from os.path import join
from time import sleep
class SMTPPage(BasePage):
    url='/crm5/index.php?m=setting&a=smtp'
    # 邮箱地址定位器
    smtp_email_locator = (By.CSS_SELECTOR,
                          '#address')
    # smtp定位器
    smtp_address_locator = (By.ID, 'smtp')
    # 端口定位器
    port_locator = (By.ID, 'port')
    # 登录
    login_name_locator = (By.ID, 'loginName')
    # 密码
    smtp_password_locator = (By.ID, 'password')
    # SSL
    secure_locator = (By.ID, 'secure')
    #设置成功并保存的定位器
    setting_success_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success')

    # 网页定位器
    xy_locator = (By.TAG_NAME, 'html')
    # 保存按钮
    btn_save_locator = (By.CSS_SELECTOR,
                        'body > div.container > div.tabbable > div > form > table > tbody > tr:nth-child(14) > td:nth-child(2) > input')

    def input_smtp_email(self, email='228329544@qq.com'):
        """输入邮箱地址的方法"""
        self.driver.find_element(*self.smtp_email_locator).clear()
        self.driver.find_element(*self.smtp_email_locator).send_keys(email)
    def input_smtp_address(self, address='smtp.qq.com'):
        """输入一个smtp服务器的地址"""
        self.driver.find_element(*self.smtp_address_locator).clear()
        self.driver.find_element(*self.smtp_address_locator).send_keys(address)
    def input_port(self, port=25):
        """输入一个端口号"""
        self.driver.find_element(*self.port_locator).clear()
        self.driver.find_element(*self.port_locator).send_keys(port)
    def input_login_name(self, login_name='LoginName'):
        """输入登录名"""
        self.driver.find_element(*self.login_name_locator).clear()
        self.driver.find_element(*self.login_name_locator).send_keys(login_name)
    def input_password(self, password='123456'):
        """输入一个密码"""
        self.driver.find_element(*self.smtp_password_locator).clear()
        self.driver.find_element(*self.smtp_password_locator).send_keys(password)
    def click_save_btn(self):
        # 滑动页面到最下面
        xy = self.driver.find_element(*self.xy_locator).size
        js = 'window.scroll(0, %s)' % (xy['height'])
        self.driver.execute_script(js)
        sleep(1)
        # 点击保存
        self.driver.find_element(*self.btn_save_locator).click()
    def click_ssl(self):
        """勾选SSL"""
        self.driver.find_element(*self.secure_locator).click()
    def get_seting_success_text(self):
        """获取设置成功提示信息"""
        return self.driver.find_element(*self.setting_success_locator).text